package com.linyu.huawei.simple;


import java.util.*;
import java.util.stream.Collectors;

/**
 * 拔河比赛
 *
 * 用数组做最好，省的创建对象的类
 */
public class TugOfWar {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = 2;
        ArrayList<TugOfWarPerson> list = new ArrayList<>();
        System.out.println("请依次输入人员的身份，体重；再输入下一个人的（默认10个人）：");
        for (int i = 1; i <= num; i++) {
            System.out.println("请输入第"+ i +"个人:");
            int height = sc.nextInt();
            int weight = sc.nextInt();
            TugOfWarPerson tugOfWarPerson = new TugOfWarPerson(height, weight);
            list.add(tugOfWarPerson);
        }
        // 处理处理
        Collections.sort(list, new Comparator<TugOfWarPerson>() {
            @Override
            public int compare(TugOfWarPerson o1, TugOfWarPerson o2) {
                // 身高优先，体重其次
                if (o1.getHeight() > o2.getHeight()){
                    return 1;
                }else if (o1.getHeight() < o2.getHeight()){
                    return -1;
                }
                // 身高相同情况
                if (o1.getWeight() > o2.getWeight()){
                    return 1;
                }else if (o1.getWeight() < o2.getWeight()){
                    return -1;
                }
                return 1;
            }
        });
        List<TugOfWarPerson> result = list.stream().limit(10).collect(Collectors.toList());
        for (TugOfWarPerson bean : result) {
            System.out.println(bean.getHeight() + " " + bean.getWeight());
        }
    }
}

class TugOfWarPerson{
    private Integer height;
    private Integer weight;

    public TugOfWarPerson(){}
    public TugOfWarPerson(Integer height, Integer weight){
        this.height = height;
        this.weight = weight;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TugOfWarPerson that = (TugOfWarPerson) o;
        return Objects.equals(height, that.height) && Objects.equals(weight, that.weight);
    }

    @Override
    public int hashCode() {
        return Objects.hash(height, weight);
    }

    @Override
    public String toString() {
        return "TugOfWarPerson{" +
                "height=" + height +
                ", weight=" + weight +
                '}';
    }
}